package com.lishe.lishe.lishe.module.myorder.bean;

import android.util.Log;

import com.google.gson.annotations.SerializedName;
import com.lishe.lishe.lishe.module.shopingcart.bean.StoreObject;
import com.lishe.lishe.lishe.utils.FormatUtil;

import java.io.Serializable;

/**
 * Created by lwa on 2017/8/14.
 * 商铺对象
 */

public class BusinessObject implements Serializable {

    @SerializedName("TradeData")
    private TradeDataObject TradeData = new TradeDataObject();//商店信息对象

    @SerializedName("payment_id")
    private String payment_id;//商店支付id

    @SerializedName("payment")
    private String payment;//商店支付金额

    @SerializedName("status")
    private String status;//

    @SerializedName("tid")
    private String tid;//点单id



    /**
     * 店铺下，选中的商品数
     */
    private int checkGoodsCount = 0;
    /**
     * 购物车的商店是否被全选
     */
    private boolean isCheck;

    public TradeDataObject getTradeData() {
        return TradeData;
    }

    public void setTradeData(TradeDataObject tradeData) {
        TradeData = tradeData;
    }

    public String getPayment_id() {
        return payment_id;
    }

    public void setPayment_id(String payment_id) {
        this.payment_id = payment_id;
    }

    public String getPayment() {
        if (payment == null) {
            double pay = 0;
            for (GoodObject goodObject : TradeData.getOrderList()) {
                if (goodObject.isCheck()) {
                    pay = pay + (Double.parseDouble(goodObject.getPrice()) * goodObject.getNum());
                }
            }
            return FormatUtil.numFormat(pay);
        }
        return payment;
    }

    public void setPayment(String payment) {
        this.payment = payment;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getTid() {
        return tid;
    }

    public void setTid(String tid) {
        this.tid = tid;
    }

    public int getCheckGoodsCount() {
        checkGoodsCount = 0;
        for (GoodObject goodObject : TradeData.getOrderList()) {
            if (goodObject.isCheck()) {
                checkGoodsCount = checkGoodsCount + 1;
            }
        }
        return checkGoodsCount;
    }

    public boolean isCheck() {
        return isCheck;
    }

    public void setCheck(boolean check) {
        isCheck = check;
    }

    /**
     * 复制已经知道的类
     */
    public void copy(BusinessObject object) {
        TradeData.setShopName(object.getTradeData().getShopName());
        setCheck(object.isCheck);
//        setBusinessDescribe(object.TradeData.gett);
        TradeData.setShop_id(object.getTradeData().getShop_id());
        setPayment_id(object.getPayment_id());
        TradeData.setPost_fee(object.getTradeData().getPost_fee());
        TradeData.setStatus(object.getTradeData().getStatus());
        setTid(object.getTid());
        TradeData.getOrderList().clear();
        TradeData.getOrderList().addAll(object.TradeData.getOrderList());
        Log.e("保存金额", object.getPayment() + "");
        setPayment(object.getPayment());
    }

    /**
     * 复制已经知道的类
     */
    public void copy(StoreObject object) {
        TradeData.setShopName(object.getShop_name());
        setCheck(object.isCheck());
//        setBusinessDescribe(object.TradeData.gett);
        TradeData.setShop_id(object.getShop_id());
        TradeData.getOrderList().clear();
        for (com.lishe.lishe.lishe.module.shopingcart.bean.GoodObject goodObject : object.getGoodObjects()) {
            GoodObject goodObject1 = new GoodObject();
            goodObject1.setCartId(goodObject.getCart_id());
            goodObject1.setPic_path(goodObject.getImage_default_id());
            goodObject1.setItem_id(goodObject.getItem_id());
            goodObject1.setMkt_price(goodObject.getMkt_price());
            goodObject1.setPrice(goodObject.getPrice());
            goodObject1.setNum(goodObject.getQuantity());
            goodObject1.setShop_id(goodObject.getShop_id());
            goodObject1.setSku_id(goodObject.getSku_id());
            goodObject1.setSpec_info(goodObject.getSpec_info());
            goodObject1.setTitle(goodObject.getTitle());

            TradeData.getOrderList().add(goodObject1);
        }
        setPayment(FormatUtil.numFormat(object.getPayment()));
    }
}

